﻿@using System.Web.Mvc
@using System.Web.Mvc.Html
@using Microsoft.Web.Helpers;
@using VocaDb.Model.DataContracts
@using VocaDb.Model.DataContracts.PVs
@using VocaDb.Model.Domain
@using VocaDb.Model.Domain.ExtLinks
@using VocaDb.Web.Helpers
@inherits VocaDb.Web.Code.HelperPage
	
@helper DeletedBanner(IEntryBase mergedTo) {
	<div class="alert">
		@Resources.CommonMessages.EntryDeleted
		@if (mergedTo != null) {
			@(Resources.CommonMessages.EntryMergedTo + " ")
			@Helpers.EntryLink(new EntryBaseContract(mergedTo))
			@(".")
		}		
	</div>
}

@helper EntryDeletePopupBase(string confirmText, string viewModelBindingName,  string deleteButtonId, string title, string deleteButtonText) {

	<div style="display:none;" title="@title"
		data-bind="
		dialog: {
			autoOpen: false, width: 310, modal: true,
			position: { my: 'left top', at: 'left bottom', of: $('#@deleteButtonId') }
		},
		dialogVisible: @(viewModelBindingName).dialogVisible,
		dialogButtons: [
			{ text: '@deleteButtonText', click: @(viewModelBindingName).deleteEntry }, 
			{ text: '@ViewRes.SharedStrings.Cancel', click: function() { @(viewModelBindingName).dialogVisible(false); } }
		]
		">

		<p>
			@confirmText
		</p>

		<textarea data-bind="textInput: @(viewModelBindingName).notes" class="input-xlarge" maxlength="200"></textarea>

	</div>

}

@helper EntryDeletePopup(string confirmText, string viewModelBindingName = "deleteViewModel", string deleteButtonId = "deleteLink") {
	@EntryDeletePopupBase(confirmText, viewModelBindingName, deleteButtonId, ViewRes.SharedStrings.Delete, ViewRes.SharedStrings.Delete)	
}

@helper EntryTrashPopup(string confirmText, string viewModelBindingName = "trashViewModel",  string deleteButtonId = "trashLink") {
	@EntryDeletePopupBase(confirmText, viewModelBindingName, deleteButtonId, ViewRes.EntryEditStrings.MoveToTrash, ViewRes.EntryEditStrings.MoveToTrash)
}

@helper ExternalLinksList(IEnumerable<WebLinkContract> webLinks, bool showCategory = false) {
    
    foreach (var link in webLinks) {
        <a class="extLink" href="@VocaDb.Model.Service.Helpers.UrlHelper.MakePossileAffiliateLink(link.Url)" onclick="vdb.functions.trackOutboundLink(event)">@link.DescriptionOrUrl</a>
        if (showCategory) {
            @("(")@Translate.WebLinkCategoryNames[link.Category]@(")")
        }
        <br />
	}		
    	    
}

@helper ExternalLinksRows(ICollection<WebLinkContract> webLinks) {
    
    var official = webLinks.Where(l => l.Category == WebLinkCategory.Official || l.Category == WebLinkCategory.Commercial).ToArray();
    var other = webLinks.Where(l => !official.Contains(l)).ToArray();
    
    if (official.Any()) {
        <tr>
            <td>@ViewRes.EntryDetailsStrings.OfficialLinks</td>
            <td>
                @ExternalLinksList(official, false)
            </td>	
        </tr>
    }    

    if (other.Any()) {
        <tr>
            <td>@ViewRes.EntryDetailsStrings.OtherLinks</td>
            <td>
                @ExternalLinksList(other, true)
            </td>	
        </tr>
    }    
        
}
		  
@helper ReportEntryPopup(MvcHtmlString reportTypesDropdown) {
	
<div id="reportEntryPopup" style="display:none;" title="@ViewRes.EntryDetailsStrings.ReportAnError">
	
	<label>
		@ViewRes.EntryDetailsStrings.ReportType
	</label>
	@reportTypesDropdown
	
	<label>
		@ViewRes.EntryDetailsStrings.ReportNotes
	</label>
	@Html.TextArea("reportNotes", new { id = "reportNotes", @class = "input-xlarge" })

</div>

}

@helper ReportEntryPopupKnockout(string viewModelBindingName = "reportViewModel", string reportButtonId = "reportEntryLink") {

	<div style="display:none;" title="@ViewRes.EntryDetailsStrings.ReportAnError"
		 data-bind="
			with: @viewModelBindingName,
			dialog: {
				autoOpen: false, width: 315,
				position: { my: 'left top', at: 'left bottom', of: $('#@reportButtonId') }
			},
			dialogVisible: @(viewModelBindingName).dialogVisible,
			dialogButtons: [{ text: '@ViewRes.SharedStrings.Save', click: @(viewModelBindingName).send, disabled: !@(viewModelBindingName).isValid() }]">

		<label>
			@ViewRes.EntryDetailsStrings.ReportType
		</label>
		<select data-bind="value: reportType, options: reportTypes, optionsText: 'name'"></select>

		<label>
			@ViewRes.EntryDetailsStrings.ReportNotes
			<span data-bind="visible: (reportType() && reportType().notesRequired)">@ViewRes.EntryDetailsStrings.ReportNotesRequired</span>
		</label>
		<textarea data-bind="textInput: notes" class="input-xlarge" maxlength="400"></textarea>

	</div>

}

@helper ReportEntryVersionPopupKnockout(string viewModelBindingName = "reportViewModel", string reportButtonId = "reportEntryLink") {

	<div style="display:none;" title="@ViewRes.EntryDetailsStrings.ReportAnError"
		 data-bind="
			with: @viewModelBindingName,
			dialog: {
				autoOpen: false, width: 310,
				position: { my: 'left top', at: 'left bottom', of: $('#@reportButtonId') }
			},
			dialogVisible: @(viewModelBindingName).dialogVisible,
			dialogButtons: [{ text: '@ViewRes.SharedStrings.Save', click: @(viewModelBindingName).send, disabled: !@(viewModelBindingName).isValid() }]">
		
		<p>
			@ViewRes.EntryDetailsStrings.ReportArchivedVersionExplanation
		</p>

		<label>
			@ViewRes.EntryDetailsStrings.ReportArchivedVersionMessage
		</label>
		<textarea data-bind="textInput: notes" class="input-xlarge" maxlength="400" rows="3"></textarea>

	</div>

}

@helper ShareLinks(string title, string url) {
	@(ViewRes.EntryDetailsStrings.Share + ":")
	@LinkShare.GetHtml(title, pageLinkBack: url, linkSites: new[] { LinkShareSite.Facebook, LinkShareSite.Reddit, LinkShareSite.Twitter })	
}

@helper LargeShareLinks(string title, string url) {
	var urlEncodedTitle = Url.Encode(title);
	<a href="https://www.facebook.com/sharer/sharer.php?u=@url" target="_blank"><img alt="Share on Facebook" src="@Url.Content("~/Content/ExtIcons/facebook32.png")" style="border:0; height:32px; width:32px; margin:0 1px;" title="Share on Facebook"></a>
	<a href="http://reddit.com/submit?url=@url&title=@urlEncodedTitle" target="_blank" title="Reddit!"><img alt="Reddit!" src="@Url.Content("~/Content/ExtIcons/reddit32.png")" style="border:0; height:32px; width:32px; margin:0 1px;" title="Reddit!"></a>
	<a href="http://twitter.com/home/?status=@urlEncodedTitle: @url" target="_blank" title="Share on Twitter"><img alt="Twitter" src="@Url.Content("~/Content/ExtIcons/twitter32.png")" style="border:0; height:32px; width:32px; margin:0 1px;" title="Share on Twitter"></a>
	<a href="https://plus.google.com/share?url=@url" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" title="Share on Google+"><img alt="Google+" src="https://www.gstatic.com/images/icons/gplus-32.png" style="border:0; height:32px; width:32px; margin:0 1px;" title="Share on Google+"></a>
}